import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import App from './App.vue'
import router from './router'
import SvgIcon from '@/components/iconfont/SvgIcon.vue'
import '@/components/iconfont/iconfont.js'

//element-plus组件汉化
import 'dayjs/locale/zh-cn'
import locale from 'element-plus/es/locale/lang/zh-cn'

import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import mitt from 'mitt'
import { genarateRouter } from '@/utils/util'

const app = createApp(App)
const bus = mitt()
app.config.globalProperties.$bus = bus //相当于Vue2中的:Vue.prototype.$bus = bus

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(createPinia())
// const routes = JSON.parse(localStorage.getItem('customRoutes')) ?? []
// const newRoutes = genarateRouter(routes)
// newRoutes.forEach((item) => {
//   router.addRoute(item)
// })

app.component('SvgIcon', SvgIcon)
app.use(ElementPlus, { locale })
app.use(router)

// 确保路由加载完毕后再挂载应用
router.isReady().then(() => {
  app.mount('#app')
})
